package com.appcheck.recording.listener.impl;

import android.view.View;
import android.widget.ExpandableListView;
import android.widget.ExpandableListView.OnChildClickListener;

import com.appcheck.recording.ListenerManager;
import com.appcheck.recording.WidgetHelper;
import com.appcheck.recording.action.impl.ItemClickAction;
import com.appcheck.recording.listener.AbstractListener;
import com.appcheck.recording.utils.Logger;

public class ChildClickListener extends AbstractListener implements
		OnChildClickListener {

	private int b;
	public ChildClickListener(View paramView) {
		super(paramView, ExpandableListView.class, ExpandableListView.OnChildClickListener.class);
	}

	@Override
	public final boolean onChildClick(ExpandableListView parent, View v,
			int groupPosition, int childPosition, long id) {
		
	    if (this.b++ > 1) {
	        return false;
	      }
	    //groupPosition是组的位置，childPosition是组内的位置，id和childPosition相同
	    //Logger.INFO("onChildClick groupPosition = " + groupPosition + ", " + "childPosition = " + childPosition + " id = " + id + ", parent.indexOfChild = " + parent.indexOfChild(v) + ", " + "parent.getPositionForView = " + parent.getPositionForView(v));
	    ItemClickAction itemClickAction = new ItemClickAction();
	    itemClickAction.setLine(parent.getPositionForView(v));
	    itemClickAction.setLongClick(false);
	    itemClickAction.setParentResourceId(WidgetHelper.getResourceId(parent));
	    itemClickAction.setParentResourceName(WidgetHelper.getResourceName(parent));
	    ListenerManager.getListenerManager().handleAction(itemClickAction);
	    if (this.listener != null){
	    	boolean bool = ((ExpandableListView.OnChildClickListener)this.listener).onChildClick(parent, v, groupPosition, childPosition, id);
	        this.b = 0;
	        return bool;
	    }
	    this.b = 0;
	    return false;
	}

}
